<?php
include '../admin_head.php';
//include '../common.php';

//处理搜索分页数据
	$name = $_GET['name'];
	$order_id = $_GET['order_id'];
	$goods_id = $_GET['goods_id'];
	$com_id = $_GET['com_id'];
	
	if($name != null) $search[] = "user_name like '%{$name}%'";
	if($order_id != null) $search[] = "order_id = '{$order_id}'";
	if($goods_id != null) $search[] = "goods_id = '{$goods_id}'";
	if($com_id != null) $search[] = "id = '{$com_id}'";
	
	if($search != null ) $where = 'where '. implode(' and ',$search);

	$where = empty($_GET['where']) ? $where : stripslashes($_GET['where']);

//获取总记录数
    $sql = "select count(id) num from ". PRE ."comment {$where}" ;
    
    $result = mysql_query($sql);
    
    if($result && mysql_affected_rows() > 0){
        $row = mysql_fetch_assoc($result);
    }

    $total = $row['num'];       //总记录数
    //每页显示数
    $num = 10;

    //总页数
    $amount = ceil($total / $num);

    //页码
    $page = empty($_GET['p'])? 1 : (int)$_GET['p'];

    if($page < 1){
        $page = 1;
    }

    if($page > $amount){
        $page = $amount;
    }

    //偏移量
    $offset = ($page - 1) * $num;  



$sql = "select * from ".PRE."comment {$where} order by order_id desc,goods_id,addtime limit {$offset},{$num}";
$result = mysql_query($sql);
if($result && mysql_num_rows($result) > 0){
	while($row = mysql_fetch_assoc($result)){
		$comlist[] = $row;
	}
}

//制作分页按钮
 $start = ($page - 3) <= 1 ? 1 : $page - 3;

    $end = ($page + 3) >= $amount ? $amount : $page + 3 ;

    for($i = $start; $i <= $end; $i++){
        if($i == $page){
            $str .= '<li><a style="color:#E50065;font-weight:bold;" href="index.php?where='.$where.'&p='. $i .'" >['. $i .']</a></li>';
            continue;
        }
            $str .= '<li><a href="index.php?where='.$where.'&p='. $i .'">['. $i .']</a><li>';

    }

    $nav = <<<tag
        <li><a href="index.php?where={$where}&p=1">首页</a></li>
        $str
        <li><a href="index.php?where={$where}&p=$amount">尾页</a></li>
tag;



?>

	<div class="admin_main_nav">评论管理&gt;&gt;评论列表</div>
	<div id="user_index" class="admin_main_index">
		<div class="width">
			<div class="user_index_title">
				<div class="user_search fr">
					<form action="index.php" method="get">
						会员名称：<input class="shotinput" type="text" name="name"/>
						订单号：<input class="shotinput" type="text" name="order_id"/>
						商品号：<input class="shotinput" type="text" name="goods_id"/>
						评论ID：<input class="shotinput" type="text" name="com_id"/>
						<input type="submit" value="搜索" />
					</form>
				</div>	
			</div>
			<div>
				<table width="800" align="center">
					<tr>
						<th width="40">ID</th>
						<th width="100">会员名称</th>
						<th width="60">订单号</th>
						<th width="60">商品</th>
						<th width="120">评论时间</th>
						<th>评论内容</th>
						<th width="50">显示</th>
						<th width="80">操作</th>
					</tr>
					<?php if(!empty($comlist)):?>
					<?php foreach($comlist as $tr):?>
					<tr>
						<td><?php echo $tr['id']?></td>
						<td><?php echo $tr['user_name']?></td>
						<td><?php echo $tr['order_id']?></td>
						<td><?php
							$sql = "select id,cate_id,name,image from ".PRE."goods where id='{$tr[goods_id]}'";
							$goodsinfo = mysql_fetch_assoc(mysql_query($sql));?>
							<a href="<?php echo APP.'/detail.php?gid='.$goodsinfo['id'].'&cid='.$goodsinfo['cate_id']?>" target="_top"><img src="<?php echo APP.'/upload/'.$goodsinfo['image']?>" height="50" title="<?php echo $goodsinfo['name']?>"/></a> 
						</td>
						<td><?php echo date('Y-m-d H:i:s',$tr['addtime']) ?></td>
						<td><?php echo $tr['content'] ?></td>
						<td><?php 
							if($tr['display'] == 0) echo '<a href="action.php?a=dis&page='.$page.'&dis=1&id='.$tr['id'].'"><img src="../../images/no.gif" /></a>';
							if($tr['display'] == 1) echo '<a href="action.php?a=dis&page='.$page.'&dis=0&id='.$tr['id'].'"><img src="../../images/yes.gif" /></a>';
						?></td>
						<td>
							<div class="action">
								<div class="fl"><a class="del" href="action.php?a=del&id=<?php echo $tr[id] ?>"><div class="icon fl del_i"></div><div class="fl">删除</div></a></div>
							</div>
						</td>
					</tr>
					<?php endforeach;?>
					<?php else:?>
						<tr>
							<td colspan="8">没有找到任何记录</td>
						</tr>
					<?php endif;?>
				</table>
			</div>
			<!-- 分页按钮 -->
			<div class="nav">
				<div class="tips"><?php $start = $offset + 1>0? $offset+1: 0;$end = $offset + $num >= $total? $total : $offset + $num; echo "Showing $start to $end of $total entries";?></div>
				<ul class="user_nav">
					<?php echo $nav?>
				</ul>
			</div>
		</div>
	</div>

	
<?php include '../admin_footer.php'; ?>

